﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CF_DAL_WS.Models;

namespace CF_DAL_WS.DTO
{
    public class MenuDTO
    {
        public int ID { get; set; }
        public int IDRestaurant { get; set; }
        public string Name { get; set; }
        public List<FoodDTO> Foods { get; set; }

        public static MenuDTO Translate(Menu Entity)
        {
            if (Entity != null)
            {
                var dto = new MenuDTO
                {
                    ID = Entity.ID,
                    Name = Entity.Name,
                    Foods = new List<FoodDTO>()
                };
                if (Entity.IDRestaurant != null)
                {
                    dto.IDRestaurant = Entity.IDRestaurant.Value;
                }
                if (Entity.Food != null)
                {
                    foreach (var item in Entity.Food)
                    {
                        dto.Foods.Add(FoodDTO.Translate(item));
                    }
                }
                return dto;
            }
            return null;
        }

        public static MenuDTO TranslateBase(Menu Entity)
        {
            if (Entity != null)
            {
                var dto = new MenuDTO
                {
                    ID = Entity.ID,
                    Name = Entity.Name
                };
                if (Entity.IDRestaurant != null)
                {
                    dto.IDRestaurant = Entity.IDRestaurant.Value;
                }
                return dto;
            }
            return null;
        }

        public static Menu Reverse(MenuDTO obj)
        {
            var entity = new Menu
            {
                Name = obj.Name
            };
            if (obj.IDRestaurant != -1)
            {
                entity.IDRestaurant = obj.IDRestaurant;
            }
            return entity;
        }

        public void UpdateEntity(ref Menu entity)
        {
            entity.Name = Name;
            if (IDRestaurant != -1)
            {
                entity.IDRestaurant = IDRestaurant;
            }
        }
    }
}